Class EvtAid
static var lastTouchNum=0;
static var lastDocW=0;
static var touchStartY;
static var exitHintLabel;
static var gestureStep=0;
//!!在跳转前需重置isIosFirstBack=true;
static var isIosFirstBack=true;
public static function init(){
	Me.lastDocW=document.documentElement.clientWidth;
	if(G.os==1){
		window.onmousedown=Me.onMouseEvent;
		window.onmouseup=Me.onMouseEvent;
		window.onmousemove=Me.onMouseEvent;
		window.onkeydown=Me.onKeyDown;
	}
	else{
		window.ontouchstart=Me.onTouchEvent;
		window.ontouchmove=Me.onTouchEvent;
		window.ontouchend=Me.onTouchEvent;
	}
	Me.isIosFirstBack=true;
	window.onresize=Me.onResize;
	Me.playTime();
}
static function onMouseEvent(evt){
	if(evt.button==2){
		if(Shell){
			GAid.createQRLink();
		}
		GAid.resetChanged();
		return;
	}
	var ex=int(evt.clientX/G.scale);
	var ey=int(evt.clientY/G.scale);
	if(evt.type=="mousedown"){
		G.touchs=[[ex,ey]];
	}
	else if(evt.type=="mousemove"){
		if(G.touchs.length==0) return;
		G.touchs=[[ex,ey]];
	}
	else if(evt.type=="mouseup"){
		G.touchs=[];
	}
	Me.onEvent(evt);
	if(evt.type=="mouseup"&&GAid.qrBox){
		GAid.qrBox.remove();
		GAid.qrBox=null;
	}
}
static function onTouchEvent(evt){
	G.touchs=[];
	var touches=evt.touches;
	var ex=0;
	var ey=0;
	for(var i=0;i<touches.length;i++){
		var t=touches[i];
		ex=int(t.clientX/G.scale);
		ey=int(t.clientY/G.scale);
		G.touchs.push([ex,ey]);
	}
	Me.onEvent(evt);
	if(evt.type=="touchstart"){
		Me.touchStartY=ey;
		G.renderIos=true;
	}
	if(evt.type=="touchend"){
		Me.touchStartY=ey;
	}
	if(evt.type=="touchmove"){
		var div=evt.target;
		var prevent=true;
		while(div&&div!=document.body){
			if(div.scroll&&ey>Me.touchStartY&&div.scrollTop>0){
				prevent=false;
			}
			if(div.scroll&&ey<Me.touchStartY&&div.scrollTop+3<div.scrollHeight-div.clientHeight){
				prevent=false;
			}
			div=div.parentNode;
		}
		if(GAid.traceDiv) prevent=false;
		if(prevent) evt.preventDefault();
	}
}
static function onEvent(evt){
	var target=evt.target.box||G.stage;
	var num=G.touchs.length;
	var x=num==0?0:int(G.touchs[G.touchs.length-1][0]);
	var y=num==0?0:int(G.touchs[G.touchs.length-1][1]);
	if(num>Me.lastTouchNum){
		G.pressX=x;
		G.pressY=y;
		G.x=x;
		G.y=y;
		G.isPress=true;
		G.target=target;
		G.pressTime=G.now;
		G.holdTime=G.now;
		G.isPressMove=false;
		if(GAid.traceDiv&&evt.target!=GAid.traceDiv){
			document.body.removeChild(GAid.traceDiv);
			GAid.traceDiv=null;
		}
		G.target.dispatchEvent(G.newEvent(Evt.PRESS));
		GAid.resetChanged();
		G.isPress=true;
	}
	else if(num<Me.lastTouchNum){
		if(G.isPress){
			if(!G.isPressMove&&G.target){
				G.target.dispatchEvent(G.newEvent(Evt.CLICK));
			}
			G.target.dispatchEvent(G.newEvent(Evt.RELEASE));
			GAid.resetChanged();
		}
		G.isPress=false;
		G.target=null;
	}
	if(num>0){
		if(G.x!=x||G.y!=y){
			G.x=x;
			G.y=y;
			G.holdTime=G.now;
		}
		if(Math.distance(G.pressX,G.pressY,G.x,G.y)>10){
			G.isPressMove=true;
		}
	}
	else{
		G.holdTime=0;
	}
	Me.lastTouchNum=num;
}
static function onKeyDown(evt){
	var data={keyCode:evt.keyCode,ctrlKey:evt.ctrlKey,shiftKey:evt.shiftKey,altKey:evt.altKey,metaKey:evt.metaKey};
	G.stage.dispatchEvent(G.newEvent(Evt.KEY_DOWN,data));
	if(evt.keyCode==116){
		location.reload(true);
	}
	else if(evt.keyCode==27){
		if(G.platform==1) Me.onPopState();
	}
	else if(G.platform==1&&evt.keyCode==8&&evt.ctrlKey){
		history.back();
	}
}
static function onResize(evt){
	var docW=document.documentElement.clientWidth;
	var docH=document.documentElement.clientHeight;
	if(G.os==1){
		G.scale=docW/docH<1.57?docW/GAid.designW:docH/(GAid.designW*1.57);
		document.documentElement.style[G.toCssKey("Transform")]="scale("+G.scale+","+G.scale+")";
	}
	G.w=int(docW/G.scale);
	G.h=int(docH/G.scale);
	if(G.os>1&&G.w>G.h) G.h=GAid.designW*1.57;
	G.stage.setSize(G.w,G.h);
	G.main.setSize(G.w,G.h);
}
static function playTime(){
	if(G.isPress){
		if(Me.gestureStep==0){
			if(G.x>G.w-100) Me.gestureStep=1;
		}
		if(Me.gestureStep==1){
			if(G.x<100) Me.gestureStep=2;
		}
		if(Me.gestureStep==2){
			if(G.now-G.holdTime>300){
				Me.gestureStep=0;
				if(G.y<G.h/2){
					location.reload(true);
				}
				else if(window.Log){
					Log.show();
				}
			}
			if(G.x>100) Me.gestureStep=0;
		}
	}
	else{
		Me.gestureStep=0;
	}
	callLater([Me.playTime]);
}